package com.cx.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author zhangshuai
 * @version V1.0
 * @Project Java2_26
 * @Package com.cx.io
 * @Description:
 * @Date 2025/5/23 16:35
 */

public class FileInputStreamTest {
    public static void main(String[] args) {
        try {
            //创建FileInputStream对象，用于读取文件
            FileInputStream fileInputStream = new FileInputStream("bbb.txt");
            /*int read ;
            //read()方法每次读取一个字节，返回的是读取到的字节的ASCII码值，如果返回-1表示已经读取到文件末尾
            while((read = fileInputStream.read())  != -1 )
                System.out.print((char)read);*/
            byte[] bytes = new byte[1024];
            int len;
            while ((len = fileInputStream.read(bytes)) != -1)
                System.out.println(new String(bytes,0,len));

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}